/*******************************************************************************
 * Copyright (c) 2007 TOPCASED. All rights reserved. This program
 * and the accompanying materials are made available under the terms of the
 * Eclipse Public License v1.0 which accompanies this distribution, and is
 * available at http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors: Topcased contributors and others - initial API and implementation
 *******************************************************************************/
/**
 * This is a fork of the UML2Java Plug-in developed by Topcased and released under
 * the Eclipse EPL License. http://www.eclipse.org/legal/epl-v10.html
 * In accordance with the license, I have forked the UML2Java plugin and have adapted
 * it to suit the needs of a UML2QoS instrumentation code generator for PHP.
 * 
 * @author Alexandru Burdusel
 */
package org.topcased.uml2qos.services;

import java.util.StringTokenizer;

/**
 * String Services : methods for manipulating strings
 * 
 * @author Ariel RAMPHUL (Sopra Group - Toulouse)
 * @author Pascal GARCIA (Sopra Group - Toulouse)
 */
public class StringServices
{

    /**
     * This method returns a string corresponding to the string passed in parameter with first letter uppercase
     * 
     * @param s the string to convert to first uppercase
     * @return the string with first upper case
     * @throws Exception
     */
    public static String firstUpper(String s)
    {

        String st = "";

        if (s.length() > 0)
        {
            st = Character.toUpperCase(s.charAt(0)) + s.substring(1);
        }
        return st;
    }

    /**
     * Adds a star at each return to line inside a comment
     * 
     * @param s the string to edit
     * @return the edited string
     */
    public static String addStarsNewLines(String s)
    {
        String res = "";

        for (int i = 0; i < s.length(); i++)
        {
            res = res + s.charAt(i);
            if (s.charAt(i) == '\n')
            {
                res = res + " * ";
            }
        }

        return res;
    }

    /**
     * Generated a specified number of tabulation or space (depending of the settings)
     * 
     * @param n is the number of tab to return
     * @return a succession of tabulation or spaces
     */
    public static String addTab(int n)
    {
        String res = "";
        
        for (int i = 0; i < n; i++)
        {
        	res = res + "\t";
        }

        return res;
    }

    /**
     * Generated a tabulation of 4 spaces (depending of the settings)
     * 
     * @param c is an UML Element
     * @return a tabulation or 4 spaces
     */
    public static String addTab(org.eclipse.uml2.uml.Element c)
    {
        String res = "";
        res = res + "\t";
        return res;
    }

    /**
     * Removes spaces from a string
     * @param s
     * @return String
     */
    public static String removeSpaces(String s)
    {
    	StringTokenizer st = new StringTokenizer(s, " ", false);
    	String returnString = "";
    	
    	while(st.hasMoreElements()){
    		returnString += st.nextElement();
    	}
    	
    	return returnString;
    }
}
